﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;

namespace BHair.Base
{
    public partial class frmsplist : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public frmsplist()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void frmsplist_Load(object sender, EventArgs e)
        {
            spfenlei();
            jiazaiallsp();
        }
        /// <summary>
        /// 加载商品分类
        /// </summary>
        public void spfenlei()
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string sql = "SELECT [ID],[type]FROM [BHairDB].[dbo].[商品分类]";
            DataSet ds = new DataSet();
            SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
            sda.Fill(ds, "商品分类");
            cbofenlei.DataSource = ds.Tables["商品分类"];
            cbofenlei.DisplayMember = "type";
            conn.Close();
        }
        /// <summary>
        /// 加载全部商品
        /// </summary>
        public void jiazaiallsp()
        {
            SqlConnection conn = new SqlConnection(constr);
            conn.Open();
            string sql = "SELECT [iid] as 商品编号  ,[jianpin] as 简码,[iname] as 商品名称,[ifprice] as 进货单价,[iuprice] as 预售单价 ,[inprice] as 次数单价 ,[itype] as 商品分类 ,case[iconvert] when 0 then '是' when 1 then '否' end as 是否积分,[ireadme] as 说明,case [istatus] when 0 then '可用' when 1 then '下架'end as 状态 ,case Isbonus when 0 then'否' when 1 then'是' end as 打折 FROM [BHairDB].[dbo].[items] where iid!=1000";
            DataTable dt = new DataTable();
            SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
            sda.Fill(dt);
            this.dataGridView1.DataSource = dt;
            conn.Close();

        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            chuanzhi.xiuzeng = 0;
            frmspitem sp = new frmspitem();
            sp.ShowDialog();
            jiazaiallsp();
        }

        private void btnModify_Click(object sender, EventArgs e)
        {
            chuanzhi.xiuzeng = 1;
             if (this.dataGridView1.CurrentRow != null)
             {
                int iId = int.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString());
                frmspitem objfrmItems = new frmspitem(iId);
                chuanzhi cz = new chuanzhi();
                cz.rizhi("修改项目");
                objfrmItems.ShowDialog();
                jiazaiallsp();
                 
             }

             
           /* frmspitem sp = new frmspitem();
            sp.ShowDialog();
            */
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView1.CurrentRow != null)
            {
                chuanzhi.xiuzeng = 1;
                int iId = int.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString());
                frmspitem objfrmItems = new frmspitem(iId);
                objfrmItems.ShowDialog();
                jiazaiallsp();
            }
        }

        private void btnDown_Click(object sender, EventArgs e)
        {

        }
    }
}
